package burp;

import sqlInject.api.SqlInjectCheck;
import ui.Model;
import validate.Validate;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * Created by shuaidong on 2017/6/25.
 */
public class SqlScannerCheck implements IScannerCheck,IScannerListener {
    public PrintWriter stdout;
    public IBurpExtenderCallbacks callbacks;
    public SqlInjectCheck sqlInjectCheck;
    public Validate validate;
    public ScannerInsertPointProvider pointProvider;

    public SqlScannerCheck(PrintWriter stdout, IBurpExtenderCallbacks callbacks, SqlInjectCheck sqlInjectCheck, Validate validate, ScannerInsertPointProvider pointProvider) {
        this.stdout = stdout;
        this.callbacks = callbacks;
        this.sqlInjectCheck = sqlInjectCheck;
        this.validate = validate;
        this.pointProvider = pointProvider;

    }


    public List<IScanIssue> doPassiveScan(IHttpRequestResponse baseRequestResponse) {
        if (!Model.getInstanceModel().isSwitchSqlinject()){
            return null;
        }


        if (Validate.isblackOn){
            if (validate.patchBlackList(baseRequestResponse)){
                return null;
            }
        }
        if (Validate.iswhiteOn){
            if (!validate.patchWhiteList(baseRequestResponse)){
                return null;
            }
        }
        //进行sql注入检查
        IRequestInfo requestInfo = callbacks.getHelpers().analyzeRequest(baseRequestResponse);
        byte contentType = requestInfo.getContentType();

        if (requestInfo.getMethod().equals("GET")){
            this.sqlInjectCheck.doGetCheck(baseRequestResponse);

        }
        if (requestInfo.getMethod().equals("POST")){
          //  stdout.println("POST contenttype:"+requestInfo.getContentType());
            this.sqlInjectCheck.doPostCheck(baseRequestResponse);
        }

        return null;
    }

    public List<IScanIssue> doActiveScan(IHttpRequestResponse baseRequestResponse, IScannerInsertionPoint insertionPoint) {
        return null;
    }

    public int consolidateDuplicateIssues(IScanIssue existingIssue, IScanIssue newIssue) {
        return 0;
    }

    public void newScanIssue(IScanIssue issue) {

        stdout.println(issue.getIssueName()+"121212");
    }


}
